<%
layout("/layouts/platform.html"){
%>
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-primary navbar-btn" href="${base}/platform/wx/reply/conf/${type!}?wxid=${wxid!}" data-pjax><i
                class="ti-angle-left"></i> 返回</a>
    </div>
</header>

<div class="content-wrap">
    <div class="wrapper" style="min-height:500px;">
        <section class="panel panel-form">
            <form id="addForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
                  action="${base}/platform/wx/reply/conf/${type!}/editDo" method="post">
                <input id="content" name="content" type="hidden">
                <input id="type" name="type" type="hidden" value="${type!}">
                <input id="wxid" name="wxid" type="hidden" value="${wxid!}">
                <input id="id" name="id" type="hidden" value="${obj.id!}">

                <div class="row mb10">
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label for="appname" class="col-sm-2 control-label">公众号</label>

                            <div id="appname" class="col-sm-8" style="padding-top: 6px;">
                                ${config.appname!}
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="content" class="col-sm-2 control-label">绑定事件</label>

                            <div class="col-sm-8" style="padding-top: 6px;">
                                <% if(type == 'follow'){ %>
                                关注事件
                                <% }else{ %>
                                关键词事件
                                <% } %>
                            </div>
                        </div>
                        <% if(type == 'keyword'){
                        %>
                        <div class="form-group">
                            <label for="content" class="col-sm-2 control-label">关键词</label>

                            <div class="col-sm-8">
                                <input name="keyword" type="text" data-parsley-required="true" class="form-control"
                                       data-parsley-maxlength="20" readonly value="${obj.keyword!}">

                            </div>
                        </div>
                        <%
                        } %>
                        <div class="form-group">
                            <label for="content" class="col-sm-2 control-label">绑定类型</label>

                            <div class="col-sm-8">
                                <div class="radio"><label>
                                    <input type="radio" name="msgType" value="txt" <%if(obj.msgType=='txt'){%>checked<%}%>>文本消息</label></div>

                                <div class="radio"><label> <input type="radio" name="msgType" value="news" <%if(obj.msgType=='news'){%>checked<%}%>>图文消息</label></div>


                            </div>
                        </div>
                        <div class="form-group">
                            <label for="content" class="col-sm-2 control-label">消息内容</label>

                            <div class="col-sm-8">
                                <div class="btn-group tool-button">
                                    <a class="btn btn-primary navbar-btn" id="sel"> 选择内容</a>
                                    <a class="btn btn-danger navbar-btn" id="del">清除内容</a>

                                </div>
                                <div class="dd" id="nestable3">
                                    <ol class="dd-list">
                                        <%if(obj.msgType=='txt'){%>
                                        <li class="dd-item dd3-item" data-id="${txt.id!}"><div class="dd-handle dd3-handle">Drag</div><div class="dd3-content">${txt.title!}<i class="fa fa-close pull-right" onclick="delContent('${txt.id!}')"></i> </div></li>
                                        <%}else{%>
                                            <%for(n in news){%>
                                        <li class="dd-item dd3-item" data-id="${n.id!}"><div class="dd-handle dd3-handle">Drag</div><div class="dd3-content">${n.title!}<i class="fa fa-close pull-right" onclick="delContent('${n.id!}')"></i> </div></li>
                                            <%}%>
                                        <%}%>
                                    </ol>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-3"></div>
                <div class="col-lg-6">
                    <div class="form-group text-center">
                        <label></label>

                        <div>
                            <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交..." id="submit">提 交
                            </button>
                        </div>
                    </div>
                </div>
            </form>
        </section>

    </div>
</div>
<div id="dialogSelect" class="modal fade bs-modal-sm" tabindex="-3" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">

        </div>
    </div>
</div>
<script language="JavaScript">
    var msgtype;
    function delContent(id) {
        $("li[data-id="+id+"]").remove();
    }
    $(document).ready(function () {
        $("#nestable3").nestable();
        $('input:radio[name=msgtype]').click(function () {
            $("#nestable3 .dd-list").html("");
        });
        $("#dialogSelect").on("hidden.bs.modal", function () {
            $(this).removeData("bs.modal");
        });
        $("#sel").on("click", function () {
            var msgtype = $('input:radio[name=msgType]:checked').val();
            $("#dialogSelect").modal({
                remote: "${base}/platform/wx/reply/conf/${type!}/select?msgType=" + msgtype+"&wxid=${wxid!}"
            });
        });
        $("#del").on("click", function () {
            $("#nestable3 .dd-list").html("");
        });
        $("#submit").on("click", function () {
            var data = $("#nestable3").nestable('serialize');
            var ids = [];
            if (data) {
                $.each(data, function (i, n) {
                    ids.push(n.id);
                });
            }
            if (ids.length < 1 || ids.indexOf("nestable3") > -1) {
                Toast.error("请选择内容");
                return false;
            } else if (ids.length > 10) {
                Toast.error("图文消息不能大于10条");
                return false;
            }
            $("#content").val(ids.toString());
            $('#addForm').ajaxForm({
                dataType: 'json',
                beforeSubmit: function (arr, form, options) {

                    form.find("button:submit").button("loading");
                },
                success: function (data, statusText, xhr, form) {
                    if (data.code == 0) {
                        Toast.success(data.msg);

                    } else {
                        Toast.error(data.msg);
                    }
                    form.find("button:submit").button("reset");
                }
            });
        });

    });
</script>

<%}%>